<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Router extends CI_Router {

    function __construct()
    {
        parent::CI_Router();
    }

	
	
	/**
	 * Validates the supplied segments.  Attempts to determine the path to
	 * the controller.
	 *
	 * @access	private
	 * @param	array
	 * @return	array
	 */	
	function _validate_request($segments)
	{
		// Does the requested controller exist in the root folder?
		if (file_exists(APPPATH.'controllers/'.$segments[0].EXT))
		{
			return $segments;
		}

		// Is the controller in a sub-folder?
		if (is_dir(APPPATH.'controllers/'.$segments[0]))
		{		
			// Set the directory and remove it from the segment array
			$this->set_directory($segments[0]);
			$segments = array_slice($segments, 1);
			
			if (count($segments) > 0)
			{
				// Does the requested controller exist in the sub-folder?
				if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
				{
					show_404($this->fetch_directory().$segments[0]);
				}
			}
			else
			{
				$this->set_class($this->default_controller);
				$this->set_method('index');
			
				// Does the default controller exist in the sub-folder?
				if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
				{
					$this->directory = '';
					return array();
				}
			
			}

			return $segments;
		}

		// get the REQUEST_URI
		$sRequestUri = $_SERVER['REQUEST_URI'];
		
		if ($sRequestUri !== '/')
		{
			
			$sRequestUri = substr($sRequestUri, 1);
			
			/*
				$this->ci->load->model('db/views/short_urls', 'vw_short_urls');
				
				$this->ci->vw_short_urls->url_path = $sShortUrl;
				$this->ci->vw_short_urls->page_status = 'LI';
				
				$qShortUrlPage = $this->ci->vw_short_urls->get(array(), 1);
				
				if ($qShortUrlPage->num_rows() === 1)
				{
					$this->ci->load->model('db/views/pages_extended', 'vw_pages_extended');
					
					$this->ci->vw_pages_extended->page_name = $qShortUrlPage->row(0)->page_name;
					$this->ci->vw_pages_extended->page_status = 'LI';
					
					$qPage = $this->ci->vw_pages_extended->get(array(), 1);
					
					if ($qPage->num_rows() === 1)
					{
						redirect('/'.$qPage->row(0)->lang_accr.'/'.$qPage->row(0)->page_name, 'location');
						exit;	
					}
					
				}
			*/ 
			 			
		}

		// Can't find the requested controller...
		show_404($segments[0]);
	}
	// --------------------------------------------------------------------

	
	
}

?>